package com.yaoxuguang.concurrence.timer;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

/**
 * @author yaoxuguang
 * @Title: yao-interview
 * @Package com.yaoxuguang.concurrence.timer
 * @Description: 将定时任务线程变为守护线程
 * @date 2018年12月25日10:53
 */
public class RunTimerIsDaemon {
    private static Timer timer = new Timer(true);
    static public class MyTask extends TimerTask{
        @Override
        public void run() {
            System.out.println("定时任务代码运行了...,时间="+ new Date());
        }
    }

    public static void main(String[] args) {
        try {
            MyTask myTask = new MyTask();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:sss");
            String dateString = "2018-12-25 11:01:00";
            Date date = sdf.parse(dateString);
            timer.schedule(myTask,date);
        } catch (ParseException e) {
            e.printStackTrace();
        }

    }
}
